package com.preview.service.impl;

import com.feign.util.FileUtil;
import com.preview.service.PreviewService;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.io.File;

@Service
public class PreviewServiceImpl implements PreviewService {
    @Override
    public void previewIcon(String filePath) throws Exception {
        File file = new File(filePath);

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = requestAttributes.getResponse();
        ServletOutputStream outputStream = response.getOutputStream();

        FileUtil.fileIcon(file,outputStream);
    }
}
